package com.dianshang.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class DxUtils {

    /**
     * 发送验证码
     */
    public static void sendYZM(String phone,String yzm){
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tPz7z3Rqn9ZrPnpDFAz", "5x0M90YzB6U3jZcxQw139DlPM6rVSO"); // 韩从老师的accessKeyId和secret
        /** use STS Token
         DefaultProfile profile = DefaultProfile.getProfile(
         "<your-region-id>",           // The region ID
         "<your-access-key-id>",       // The AccessKey ID of the RAM account
         "<your-access-key-secret>",   // The AccessKey Secret of the RAM account
         "<your-sts-token>");          // STS Token
         **/
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("PhoneNumbers", phone);
        // 韩从老师
        request.putQueryParameter("SignName", "乐优商城"); // 短信签名
        request.putQueryParameter("TemplateCode", "SMS_199807258"); // 验证码模板
        request.putQueryParameter("TemplateParam", "{\"code\":\""+yzm+"\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

    /**
     * 赵宇：发送验证码入门
     */
    public static void main(String[] args) {
        DxUtils.sendYZM("17337386263", "123456");
    }

}